﻿using BootstrapBlazor.Components;
using Microsoft.AspNetCore.Components;
using Microsoft.Extensions.Localization;
using Microsoft.JSInterop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CodeMan.Application.Contracts.ClassGens;
using CodeMan.Application.Contracts;
using CodeMan.Domain.ClassGens;

using Microsoft.Extensions.Logging;

namespace CodeManDesktopBlazor.BlazorComponents.Pages
{
    /// <summary>
    /// 
    /// </summary>
    public partial class ClassGenDTOTable : ComponentBase
    {
        private IDataService<ClassGenDTOCreateUpdate> DataService { get; set; }
        private IDataService<ClassAttributeDTO> DataDetailsMainService { get; set; }
        private IDataDetailService<ClassAttributeDTO> DataDetailsService { get; set; }

        #region Inject

        [Inject]
        ILogger<ClassGenDTOTable> Logger { get; set; }

        [Inject]
        NavigationManager NavigationManager { get; set; }

        private IStringLocalizer<ClassGenDTO> Localizer { get; set; }
        /// <summary>
        ///
        /// </summary>
        [Inject]
        private IJSRuntime JSRuntime { get; set; }

        #endregion

        private IEnumerable<SelectedItem> Hobbys { get; set; }

        private int tableHeight { get; set; }
        [Parameter] public int? Width { get; set; }


        /// <summary>
        /// 
        /// </summary>
        protected override async Task OnInitializedAsync()
        {
            DataService = GData.currMainWindow.GetDataService();
            DataDetailsMainService = GData.currMainWindow.GetDataDetailsMainService();
            DataDetailsService = GData.currMainWindow.GetDataDetailsService();

            tableHeight = GData.tableHeight;
            Width = (int)(GData.mainjs.widthInt * 0.8);


            await base.OnInitializedAsync();

            //DataService.SaveAsync(new ClassGenDTOCreateUpdate() { Name = "testsave" });
            //GData.currMainWindow.DoItAsync2("CodeManDesktopBlazor");
        }

        #region OnClassAttributeDTOAdd and query

        /// <summary>
        /// 点开明细，当前行
        /// </summary>
        /// <param name="ClassGenDTO"></param>
        public void OnClickDetailRowCallback(ClassGenDTOCreateUpdate ClassGenDTO)
        {
        }
        public Task<ClassAttributeDTO> AddClassAttributeDTOsAsync(string ParentKeyId)
        {
            ClassAttributeDTO model = new ClassAttributeDTO();
            model.ClassGenId = ParentKeyId.TryToInt();
            return Task.FromResult(model);

        }
        #endregion
        #region 自定义工具栏
        private async Task DownloadAsync(IEnumerable<ClassGenDTOCreateUpdate> items)
        {
            NavigationManager.NavigateTo("CodeGens");
            await Task.CompletedTask;
        }
        #endregion

        /// <summary>
        /// 
        /// </summary>
        private static IEnumerable<int> PageItemsSource => new int[] { 4, 10, 20 };
        private Dictionary<string, IEnumerable<ClassAttributeDTO>> Cache { get; } = new();
        private static bool ShowDetailRow(ClassGenDTOCreateUpdate item) => item.Complete;
    }
}

